<?php

namespace app\api\model;

use think\Model;

/**
 * 错题库模型
 */
class Cuoti extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'createtime_text',
        'source_label_text',
        'proficiency_label_text'
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ?: ($data['createtime'] ?? '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function getSourceLabelTextAttr($value,$data)
    {
        $list = $this->getSourceList();

        //dump($data['source_label']);die;
        return $list[$data['source_label']];
    }

    public function getProficiencyLabelTextAttr($value,$data)
    {
        $list = $this->getProficiencyList();

        return $list[$data['proficiency_label']];
    }

    public function getSubjectList()
    {
        return ['yuwen'=>'语文','shuxue'=>'数学','yingyu'=>'英语','lishi'=>'历史','dili'=>'地理','zhengzhi'=>'政治','shengwu'=>'生物',
            'huaxue'=>'化学','wuli'=>'物理'];
    }

    public function getSourceList()
    {
        return [1=>'日常练习',2=>'考试试卷'];
    }

    public function getProficiencyList()
    {
        return [1=>'未掌握',2=>'基本掌握',3=>'熟悉掌握'];
    }

    public static function getSource($type)
    {
        $data = [1=>'日常练习',2=>'考试试卷'];
        return $data[$type];
    }
}
